#include<bits/stdc++.h>
# define rep(i, j, k) for (int i = j; i <= k; ++i)
# define mod 998244353
using namespace std;

int T, n, d, b, c, m;
int a[10000005], cnt[10000005];
int num[10000005], al;
int stkx[10000005], stky[10000005], r, nowx, nowy, bstx, bsty;
int power(int a, int p)
{
    int ans = 1;
    for (; p; p >>= 1) {if (p & 1) ans = 1LL * ans * a % mod; a = 1LL * a * a % mod;}
    return ans;
}
signed main()
{
    freopen("guess.in", "r", stdin);
    freopen("guess.out", "w", stdout);
    srand(time(NULL));
    ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
    cin >> T;
    while (T--)
    {
        al = nowx = nowy = 0, bstx = bsty = 1;
        cin >> n >> a[0] >> d >> b >> c >> m;
        rep(i, 1, n) ++cnt[a[i] = (1LL * d * a[i - 1] % m * a[i - 1] + 1LL * b * a[i - 1] + c) % m + 1];
        rep(i, 1, m) if (cnt[i] == 1) num[++al] = 0; else if (cnt[i] >= 2) num[++al] = 1;
        rep(i, 1, n) --cnt[a[i]];
        if (al == 1) {cout << "0.114514 1" << '\n'; continue;}
        stkx[r = 1] = stky[1] = 0;
        rep(i, 2, al)
        {
            nowx += num[i - 1] + 2, ++nowy;
            int tx = nowx + num[i], ty = nowy + 1;
            int tl = 0, tr = r;
            while (tr - tl > 1)
            {
                int mid = (tl + tr) / 2;
                if (1LL * (ty - stky[mid]) * (stkx[mid + 1] - stkx[mid]) >= 1LL * (stky[mid + 1] - stky[mid]) * (tx - stkx[mid])) tr = mid; else tl = mid;
            }
            if (1LL * (ty - stky[tr]) * bstx < 1LL * bsty * (tx - stkx[tr])) bstx = tx - stkx[tr], bsty = ty - stky[tr];
            while (r > 1 && 1LL * (nowy - stky[r]) * (stkx[r] - stkx[r - 1]) >= 1LL * (stky[r] - stky[r - 1]) * (nowx - stkx[r])) --r;
            stkx[++r] = nowx, stky[r] = nowy;
        }
        cout << "0.114514 " << 1LL * bsty * power(bstx, mod - 2) % mod << '\n';
    }
    return 0;
}
